﻿/**
* @description  Class to handle display of loaded MP3s. This requires a SoundVisualizer instance.
*/
package com.moke.media.displays {

	import flash.display.Sprite;
	
	import com.moke.media.events.MediaEvent;
	import com.moke.media.controllers.MediaController;
	import com.moke.media.controllers.MP3Controller;
	import com.moke.media.soundVisualizers.SoundVisualizer;

	public class MP3Display extends MediaDisplay {

		private var _soundVisualizer:SoundVisualizer; 
	
		/**
		* @description	Handler for the MediaController's progress, displays the sound spectrum using the visualizer.
		*
		* @param  pEvent  Event fired by MediaController.
		*/	
		private function visualizeSound(e:MediaEvent):void {
			if (_soundVisualizer != null) {
				_soundVisualizer.display(MP3Controller(getController()), displayWidth, displayHeight);
			}
		}

		/**
		* @description	Creates whatever object is necessary to load media.
		*/	
		override protected function createMediaClip():void {
			super.createMediaClip();
			_mediaClip = addChild(new Sprite());
		}
	
		/**
		* @description	Sets the MediaController whose media will be displayed.
		*
		* @param  pController  The MediaController with media to display.
		*/	
		override public function setController(pController:MediaController):void {
			super.setController(pController);
			getController().addEventListener(MediaEvent.PROGRESS, visualizeSound, false, 0, true);
		}

		/**
		* @description	Sets a SoundVisualizer for this instance, allowing fro graphical representation of the sound.
		*
		* @param  pSoundVisualizer  The SoundVisualizer instance to use to display the sound spectrum.
		*/	
		public function setVisualizer(pSoundVisualizer:SoundVisualizer):void {
			_soundVisualizer = pSoundVisualizer;
			createMediaClip();
			Sprite(_mediaClip).addChild(_soundVisualizer);
		}

	}
	
}